package com.czxy.mapper;

import com.czxy.pojo.SkuComment;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 张青卯
 */
@org.apache.ibatis.annotations.Mapper
public interface SkuCommentMapper extends Mapper<SkuComment> {

    /**
     *findCountBySpuId 查找评论数量
     * @param spuId 商品ID
     * @return Integer
     */
    @Select("select count(*) from tb_sku_comment where spu_id = #{spuId}")
    Integer findCountBySpuId(Integer spuId);

    /**
     * findAvgStarBySpuId
     * @param spuId 商品ID
     * @return Double
     */
    @Select("select avg(star) from tb_sku_comment where spu_id = #{spuId}")
    Double findAvgStarBySpuId(Integer spuId);

    @Select("SELECT * FROM tb_sku_comment WHERE spu_id = #{spuId}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "user",column = "user_id",one = @One(select = "com.czxy.mapper.UserMapper.selectByPrimaryKey"))
    })
    List<SkuComment> findSelectAll(Integer spuId);

    @Select("select count(*) from tb_sku_comment where spu_id = #{spuid} and ratio = #{ratio}")
    Integer findCommentCountByRatio(@Param("spuid")Integer spuid, @Param("ratio")Integer ratio);
}